declare var GLOBAL_IMAGE;
class SceneMange extends egret.Sprite {
	// 场景控制器的单例
	private static instance: SceneMange;
	// 游戏场景
	private gameScene: GameScene;

	private startGame;

	private resultGame;

	//记录舞台宽度
	public stageHeight: number;

	//记录舞台高度
	public stageWidth: number;

	public constructor(height,width) {
		super();
		this.stageHeight = height;
		this.stageWidth = width;
		this.init();
	}
	private init(){
		this.startGame = new BeginScene();

		this.resultGame = new ResultScene();
		// 实例化两个场景
		this.gameScene = new GameScene(this.stageHeight,this.stageWidth)

		// 默认添加开始场景
		this.addChild(this.startGame);
	}
	// 实例化单例获取方法
	public static getInstance(height?,width?): SceneMange{
		if(!SceneMange.instance){
			SceneMange.instance = new SceneMange(height,width);
		}
		return SceneMange.instance;
	}
	// 切换场景
	public changeScene(type, score?){
		// 移除所有显示列表中的对象
		this.removeChildren();

		if(type == 'resultGame'){
			let background = this.createBitmapByName('resultBg_png');
			background.height = this.stageHeight;
			background.width = this.stageWidth;
			this.addChild(background);
		}
		
		// 添加下一个场景
		this.addChild(this[type]);

		if(type == 'gameScene'){
			this.gameScene.init();
		}
		if(type == 'resultGame'){
			GLOBAL_CHANNEL = '';
			GLOBAL_IMAGE = this;
			this.resultGame.draw(score);
		}
	}
	
	private createBitmapByName(name: string): eui.Image {
        let result = new eui.Image();
        let texture: egret.Texture = RES.getRes(name);
        result.texture = texture;
        return result;
    }
}